<?php
/**
 * Created by Dumitru Russu
 * User: developer
 * Date: 10/25/12
 * Time: 11:02 AM
 * To change this template use File | Settings | File Templates.
 */
class Page_Fe_Products_Category extends Page {
	function __construct() {
		self::$TPL->appendJsFile('problems_reported');
		self::$TPL->appendJsFile('category');
        self::$TPL->appendJsFile('wedding/popup_preview');
		self::$TPL->setBodyClass('category');
		parent::__construct();
	}

	public function defaultAction() {
		if (self::$P) {
			$currentPage = self::$P;
		} else if ($paginationNumber = self::$PAGE['pp_pagination_number']) {
			$currentPage = $paginationNumber;
		} else {
			$currentPage = 1;
		}
		self::$TPL->assign('currentPage', $currentPage);
		$paginations = Db_Cms_Pages::getPaginationUrlsByPage(self::$PAGE, $currentPage);
		self::$TPL->assign('paginations', $paginations);

		$sessionProductTheme = self::$S->Get('sessionProductTheme');
		self::$TPL->assign('sessionProductTheme', $sessionProductTheme);

		$totalPaginations = count($paginations);
		self::$TPL->assign('totalPaginations', $totalPaginations);
		self::$TPL->assign('filePath', self::$PROJECT['pr_resources_live']);
		self::$TPL->setBodyTemplate('show_category');
		return array(
			'type' => 'display'
		);
	}

	public function saveProblemAction() {
		$reportedProblems = new Db_ReportedProblems();
		$reportedProblems->rp_user_ip = $_SERVER['REMOTE_ADDR'];
		$reportedProblems->rp_project_id = self::$PROJECT['id'];
		$reportedProblems->rp_type = post('type', 'str');
		$reportedProblems->rp_country = post('country', 'str');
		$reportedProblems->rp_city = post('city', 'str');
		$reportedProblems->rp_os_name = post('os_name', 'str');
		$reportedProblems->rp_email = post('email');
		$reportedProblems->rp_flash_version = post('flash_version', 'str');
		$reportedProblems->rp_memory_list_identifier = cookie(MEMORY_LIST_NAME_KEY);
		$reportedProblems->rp_phone = post('phone', 'str');
		$reportedProblems->rp_problem_content = post('problem_content', 'str');
		$reportedProblems->rp_screen_resolution = post('screen_width', 'int') . 'x' . post('screen_height', 'int');
		$reportedProblems->rp_session_id = session_id();
		$reportedProblems->rp_page = post('page', 'str');
		$reportedProblems->rp_browser = post('browser_name', 'str') . post('browser_version', 'str');
		if(!$reportedProblems->save()) {
			$this->error = true;
			$this->message = t(T_FORM_MSG, 'message_not_sent');
		}

		return array(
			'type' => 'encoded_json',
			'content' => $this->jsonResult($this->error, $this->message, !$this->error)
		);
	}

}
